<%-- 
    Document   : index
    Created on : Nov 24, 2011, 11:55:34 PM
    Author     : andrebattagello
--%>

<%@page import="classes.Categoria"%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.util.Map.Entry"%>
<%@page import="java.util.Set"%>
<%@page import="java.util.HashMap"%>
<%@page import="java.util.Map"%>
<%@page import="java.util.Date"%>
<%@page import="utils.MonthNameConverter"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="utils.WeekNameConverter"%>
<%@page import="java.util.Calendar"%>
<%@page import="java.util.GregorianCalendar"%>
<%@page import="javax.persistence.Persistence"%>
<%@page import="classes.ToDo"%>
<%@page import="java.util.List"%>
<%@page import="jpa.ToDoJpaController"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>

<% String PessoaString = (String)request.getSession().getAttribute("Pessoa"); %>
<% String CategoriaString = (String)request.getSession().getAttribute("Categoria"); %>
<% String ProjetoString = (String)request.getSession().getAttribute("Projeto"); %>

<% List<String> ToDoIntervals = (ArrayList<String>)request.getAttribute("ToDoIntervals"); %>
<% List<String> MeetingIntervals = (ArrayList<String>)request.getAttribute("MeetingIntervals"); %>
<% String monthString = (String)request.getSession().getAttribute("Month"); %>
<% String yearString = (String)request.getSession().getAttribute("Year"); %>

<% List<Categoria> categoriaList = (ArrayList<Categoria>)request.getAttribute("CategoriaList"); %>

<!DOCTYPE html>
<html>
    <head>
        <link href="style.css" rel="stylesheet" type="text/css" />
        <script type="text/javascript" src="scripts.js"></script>
        <script type="text/javascript" src="dateValidate.js"></script>
        <script type="text/javascript" src="jquery.js"></script>
        <script type="text/javascript" src="dateformat.js"></script>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Calendário CES30</title>
    </head>
    <body onload="hideBlank();">
        <%
            SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
            Calendar today = new GregorianCalendar();
            Calendar cal = new GregorianCalendar();
            int day = cal.get(Calendar.DATE);
            int month = cal.get(Calendar.MONTH);
            int year = cal.get(Calendar.YEAR);

            today.set(year, month, day, 0, 0, 0);
            
            if (monthString != null && yearString != null) {
                month = Integer.parseInt(monthString) - 1;
                year = Integer.parseInt(yearString);
            }
            
            cal.set(year, month, 1, 0, 0, 0);
            
            int daysInMonth = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
        %>
        <div id="blank"></div>
        <div id="wrapper">
            <div id="header">
                <div id="logo"><img src="images/calendar.png"/></div>
                <div id="title">Calendar - <%=MonthNameConverter.getMonthName(month+1)%>/<%=year%></div>
                <div id="filters">
                    <div id="filterAlert">
                    <%if (PessoaString == null && CategoriaString == null && ProjetoString == null) {
                        PessoaString = "Pessoa";
                        CategoriaString = "Categoria";
                        ProjetoString = "Projeto";
                    %>
                        <img id="alertIcon" src="images/alert.png" onmouseover="showMessageBox(this.id);" onmouseout="hideMessageBox();"/>
                    <%}
                        if (PessoaString == null)
                            PessoaString = "Pessoa";
                        if (CategoriaString == null)
                            CategoriaString = "Categoria";
                        if (ProjetoString == null)
                            ProjetoString = "Projeto";
                    %>
                    </div>
                    <form action="ApplyFilter" method="get">
                        <div class="formField"><div class="formInput"><input id="personFilter" class="formInputField" type="text" name="person" onfocus="clearField(this.id);" onblur="filterCheck(this.id);" value="<%=PessoaString%>"/></div></div>
                        <div class="formField"><div class="formInput">
                            <select name="category">
                                <option value="">Categoria</option>
                            <%  if(categoriaList != null) {
                                    for(Categoria c : categoriaList) {
                                        %><%=CategoriaString%><%
                                        if (CategoriaString.equals(c.getNome())) {%>
                                            <option selected value="<%=c.getNome()%>"><%=c.getNome()%></option>
                            <%          } else {%>
                                            <option value="<%=c.getNome()%>"><%=c.getNome()%></option>
                            <%          }
                                    }
                                }
                            %>
                            </select>
                        </div></div>
                        <!--<input id="categoryFilter" class="formInputField" type="text" name="category" onfocus="clearField(this.id);" onblur="filterCheck(this.id);" value="<%=CategoriaString%>"/>-->
                        <div class="formField"><div class="formInput"><input id="projectFilter" class="formInputField" type="text" name="project" onfocus="clearField(this.id);" onblur="filterCheck(this.id);" value="<%=ProjetoString%>"/></div></div>
                        <div class="formField"><div class="formInput"><input id="submitFilter" type="submit" value="Filtrar"/></div></div>
                    </form>
                </div>
            </div>
            <form action="Agenda" method="post">
            <div class="arrow leftArrow"><button onclick="decreasePage(<%=month+1%>,<%=year%>); form.submit();"><</button></div>
            <div class="arrow rightArrow"><button onclick="increasePage(<%=month+1%>,<%=year%>); form.submit();">></button></div>
            <input type="hidden" name="m" id="hiddenNextMonth"/>
            <input type="hidden" name="y" id="hiddenNextYear"/>
            </form>
            <div id="calendar">
                <div class="week">
                    <div class="dayWeek">Sunday</div>
                </div>
                <div class="week">
                    <div class="dayWeek">Monday</div>
                </div>
                <div class="week">
                    <div class="dayWeek">Tuesday</div>
                </div>
                <div class="week">
                    <div class="dayWeek">Wednesday</div>
                </div>
                <div class="week">
                    <div class="dayWeek">Thursday</div>
                </div>
                <div class="week">
                    <div class="dayWeek">Friday</div>
                </div>
                <div class="week">
                    <div class="dayWeek">Saturday</div>
                </div>
                <%
                    int i;
                    String className = "";
                    for (i=1;i<cal.get(Calendar.DAY_OF_WEEK);i++) {
                %>
                    <div class="emptyDay">
                    </div>
                <%
                    }
                    
                    for (i=1;i<=daysInMonth; i++) {
                        className = "day";
                        cal.set(year, month, i);
                        if (today.equals(cal))
                            className += " today";
                %>
                    <div id="<%=df.format(cal.getTime())%>" class="<%=className%>" onClick="showAlert('<%=df.format(cal.getTime())%>');">
                        <div class="dayNumber"><%=i%></div>
                        <div class="dayIcons">
                        <%  if(ToDoIntervals.contains(cal.getTime().toString())) {%>
                        <img src="images/taskbw.png" title="ToDo" alt="ToDo" width="24px"/>
                        <%  }%>
                        <%  if(MeetingIntervals.contains(cal.getTime().toString())) {%>
                        <img src="images/meetingbw.png" title="Meeting" alt="Meeting" width="24px"/>
                        <%  }%>
                        </div>
                        <!--<div class="dayWeek"><%=WeekNameConverter.getWeekName(cal.get(Calendar.DAY_OF_WEEK))%></div>-->
                    </div>
                <%
                    }
                %>
            </div>
        </div>
        <div id="options">
            <div class="buttonDiv" onClick="createToDo();">
                <div><img id="buttonNewTask" title="Create New Task" alt="Create New Task" src="images/star.png"/></div>
                <div>Create New Task</div>
            </div>
            <div class="buttonDiv" onClick="createNewMeeting()">
                <div><img id="buttonNewMeeting" title="Create New Meeting" alt="Create New Meeting" src="images/star.png"/></div>
                <div>Create Meeting</div>
            </div>
            <div class="buttonDiv" onClick="createNewCategory()">
                <div><img id="buttonNewCategory" title="Create New Category" alt="Create New Category" src="images/star.png"/></div>
                <div>Create Category</div>
            </div>
        </div>
        
        <%  if (request.getAttribute("sMessage") != null) { %>
                <div id="message" class="success"><%=request.getAttribute("sMessage")%></div>
        <%  } %>
        <%  if (request.getAttribute("eMessage") != null) { %>
                <div id="message" class="error"><%=request.getAttribute("eMessage")%></div>
        <%  } %>
        <div id="shade" onClick="hideAlert();">
        </div>
        <div id="tasks">
            
            <div id="toDos" class="tasksBox">
                <div class="titleTasks"> To Do's on this date: </div>
                <div id="taskList">
                
                </div>
            </div>
            <div id="meetings" class="tasksBox">
                <div class="titleTasks"> Meetings on this date: </div>
                <div id="meetingsList">
                     
                </div>
            </div>
            
        </div>
	<div id="form">
            <div><h3>Create Task</h3></div>
            <form action="CreateToDo" method="post">
                <div class="formLabel">Description:</div>   <div class="formInput"> <input class="formInputField" id="descriptionToDo" type="text" name="descriptionToDo" onfocus="clearField(this.id);"/></div>
                <div class="formLabel">Start Date:</div>    <div class="formInput"> <input class="formInputField" id="startToDo" type="text" name="startToDo" onfocus="clearField(this.id);" onblur="checkDate(this.id);"/></div>
                <div class="formLabel">End Date:</div>      <div class="formInput"> <input class="formInputField" id="endToDo" type="text" name="endToDo" onfocus="clearField(this.id);" onblur="checkDate(this.id);"/></div>
                <div class="formLabel">Category:    </div>  <div class="formInput">
                    <select name="category" id="listaCategoriasTasks">
                        <option value="">Categoria</option>
                        <%  if(categoriaList != null) {
                                for(Categoria c : categoriaList) {%>
                                    <option value="<%=c.getNome()%>"><%=c.getNome()%></option>
                        <%
                                }
                            }
                        %>
                    </select>
                </div>
                
                <div><input id="submit" disabled type="submit" value="Create"/></div>
            </form>
	</div>
        <div id="formCategory">
            <div><h3>Create New Category</h3></div>
                <div class="formLabel">Existing Categories:    </div>  <div class="formInput">
                    <select name="category" id="listaCategoriasTasks">
                        <option value="">Categoria</option>
                        <%  if(categoriaList != null) {
                                for(Categoria c : categoriaList) {%>
                                    <option value="<%=c.getNome()%>"><%=c.getNome()%></option>
                        <%
                                }
                            }
                        %>
                    </select>
                </div>
            <form action="CreateCategory" method="post">
                <div class="formLabel">Name:</div>   <div class="formInput"> <input class="formInputField" id="nameCategory" type="text" name="nameCategory" onfocus="clearField(this.id);" onblur="checkNull(this.id)"/></div>
                <div class="formLabel">Description:</div>    <div class="formInput"> <input class="formInputField" id="descriptionCategory" type="text" name="descriptionCategory" onfocus="clearField(this.id);" /></div>
                
                <div><input id="submitCategory" disabled type="submit" value="Create Category"/></div>
            </form>
	</div>    
        
        <div id="formReuniao">
            <div><h3>Create New Meeting</h3></div>
            <form action="CreateMeeting" method="post">
                <div class="formLabel">Name:        </div>  <div class="formInput"><input class="formInputField" id="nameMeeting"       type="text" name="nameMeeting" onfocus="clearField(this.id);"/></div>
                <div class="formLabel">Responsible: </div>  <div class="formInput"><input class="formInputField" id="responsibleName"   type="text" name="responsibleName" onfocus="clearField(this.id);"/></div>
                <div class="formLabel">Start Date:  </div>  <div class="formInput"><input class="formInputField" id="startMeeting"      type="text" name="dateMeeting" onfocus="clearField(this.id);" onblur="checkDate(this.id);"/></div>
                <div class="formLabel">Start Hour:  </div>  <div class="formInput"><input class="formInputField" id="startHour"         type="text" name="startHour" onfocus="clearField(this.id);"/></div>
                <div class="formLabel">End Hour:    </div>  <div class="formInput"><input class="formInputField" id="endHour"           type="text" name="endHour" onfocus="clearField(this.id);"/></div>
                <div class="formLabel">Category:    </div>  <div class="formInput">
                    <select name="category" id="listaCategoriasTasks">
                        <option value="">Categoria</option>
                        <%  if(categoriaList != null) {
                                for(Categoria c : categoriaList) {%>
                                    <option value="<%=c.getNome()%>"><%=c.getNome()%></option>
                        <%
                                }
                            }
                        %>
                    </select>
                </div>
                    
                <div class="formLabel">Observations:</div>  
                <div class="formInput"><textarea class="textArea" name="observation" onfocus="clearField(this.id);" cols=28 rows=6></textarea></div>
                <div><input id="submitMeeting" disabled type="submit" value="Create Meeting"/></div>
            </form>
	</div>
            

        <div id="movingAlert">
            Lorem ipsum dolor sit amet
        </div>
    </body>
</html>
